//
//  ViewController.m
//  作业
//
//  Created by 刘崇 on 16/10/13.
//  Copyright © 2016年 刘崇. All rights reserved.
//

#import "ViewController.h"
#import "ClassModel.h"
#import "Data.h"
#import "SECViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray * _arr;
    UITableView * _table;
}
@end

@implementation ViewController
#define MY_URL @"http://127.0.0.1/zuoye1.xml"

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //注册通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tongzhi:) name:@"Banji" object:nil];
    //
    [[Data sharedData] shujuchuli:MY_URL andBJ:@"SAX"];
    //表格
    _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 14, self.view.frame.size.height, self.view.frame.size.width)];
    _table.delegate = self;
    _table.dataSource =self;
    [self.view addSubview:_table];
    
}
#pragma mark -- delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * str= @"Mycell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
    }
    ClassModel * class = _arr[indexPath.row];
    cell.textLabel.text = class.name;
    return cell;
}
//点击单元格
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SECViewController * ssec =[[SECViewController alloc]init];
    ClassModel *class = _arr[indexPath.row];
    ssec.name = class.idname;
    [self presentViewController:ssec animated:YES completion:nil];
}
//通知回调
-(void)tongzhi:(NSNotification *)noti
{
    _arr = noti.object;
    [_table reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
